﻿


using DataWorks_Sqlite;
using Microsoft.EntityFrameworkCore;

namespace DataWorks_DAL
{
    public class DAL_Base<T> where T : class, new()
    {
        protected readonly MyDbContext _db;
        public DAL_Base(MyDbContext db)
        {
            _db = db;
        }
        public IQueryable<T> LoadEntities
          (System.Linq.Expressions.Expression<Func<T, bool>> whereLambda)
        {
            return _db.Set<T>().Where<T>(whereLambda);
        }

        public bool DeleteEntity(T entity)
        {
            _db.Entry<T>(entity).State = EntityState.Deleted;
            return true;
            //return DB.SaveChanges() > 0;
        }
        public bool EditEntity(T entity)
        {
            _db.Entry<T>(entity).State = EntityState.Modified;
            return true;
            //return DB.SaveChanges() > 0;
        }
        public bool AddEntity(T entity)
        {
            _db.Set<T>().Add(entity);
            //DB.SaveChanges();
            return true;
        }
        public bool SaveChanges()
        {
            return _db.SaveChanges() > 0;
        }

    }
}